! SUMS
!
!
module sums 
implicit none
private
public :: sum1, sum2, sum3, sum4, sum5
save

contains

function sum1(a) result(res)
real, dimension(:), intent(in) :: a
real :: res
res = sum(A)
end function

function sum2(a,n) result(res)
real, dimension(:), intent(in) :: a
integer, intent(in) :: n
real :: res
res = sum(sum(reshape(a,(/n,n/)),1))
end function

function sum3(a) result(res)
real, dimension(:), intent(in) :: a
real :: res
real :: sum = 0
integer :: i
do i=1,size(a)
    sum = sum + a(i)
enddo
res = sum
end function

function sum4(a) result(res)
real, dimension(:), intent(in) :: a
real :: res
real :: sum = 0
integer :: i
do i=size(a),1,-1
sum = sum + a(i)
enddo
res = sum
end function

function sum5(a) result(res)
real, dimension(:), intent(in) :: a
real :: res
real :: y,t,sum = 0, c=0
integer :: i
do i=1,size(a)
y = a(i)-c
t = sum + y
c = (t-sum) - y
sum = t
enddo
res = sum
end function

end module sums